package com.qf.service.impl;

import com.qf.dao.RepaymentDao;
import com.qf.loanapplication.Loanapplication;
import com.qf.loanrepayment.Loanrepayment;
import com.qf.service.RepaymentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class RepaymentServiceImpl implements RepaymentService {
    @Autowired
    RepaymentDao repaymentDao;

    @Override
    //后台查询所有
    public List<Loanrepayment> findAll() {
        return repaymentDao.findAll();
    }

    @Override
    public int deleteById(Integer id) {
        int i = repaymentDao.deleteById(id);
        if(i==1){
            return 1;
        }else {
            return 0;
        }
    }

    @Override
    public int insertOrUpdate(Loanrepayment loanrepayment) {
        Integer id = loanrepayment.getId();
        if(id==null){
            //添加
            int insert = repaymentDao.insert(loanrepayment);
            if (insert==1){
                return 1;
            }else {
                return 0;
            }
        }else{
            //修改
            int update = repaymentDao.update(loanrepayment);
            if (update==1){
                return 1;
            }else {
                return 0;
            }
        }
    }
    //前端
    @Override
    public double aApplied(Integer id) {
        return repaymentDao.aApplied(id);
    }

    @Override
    public double findPaid(Integer id) {
        return repaymentDao.findPaid(id);
    }

    @Override
    public List<Loanapplication> findBill(Integer id) {
        return repaymentDao.findBill(id);
    }

    @Override
    public Double findAlreadypaid(Integer loanapplicationd) {
        return repaymentDao.findAlreadypaid(loanapplicationd);
    }


}
